<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>简途旅行</title>
    <meta name="format-detection" content="telephone=no" />
    <meta name="wap-font-scale" content="no">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="/old/css/coupon/fetch.scss?__inline">
</head>
<body>
<div class="all_images">
    <img class="top_bg" src="" alt=""/>
    <img class="center_bg" src="/old/images/coupon/center_bg.png" alt=""/>
    <img class="bottom_bg" src="" alt=""/>
    <div class="rule-wrap">
        <img class="rule_title" src="/old/images/coupon/rule.png" alt=""/>
        <div class="rule">
            <p>1、输入手机号，点击领取，即可领取225元现金优惠！</p>
            <p>2、具体线路优惠信息参照商品详情页；</p>
            <p>3、使用抵用券和领取抵用券的手机号码需一致；</p>
            <p>4、优惠券仅简途APP可用；</p>
            <p>5、优惠券仅对简途指定商品可用，不予折现；</p>
            <p>6、在简途APP菜单栏中，点击优惠券，可查看所有优惠券信息；</p>
            <p>7、在付款界面，选择获得的优惠券即可享受优惠；</p>
            <p>8、同一商品只可使用一张优惠券；</p>
        </div>
    </div>
    <img class="footer_logo" src="/old/images/coupon/logo.png" alt=""/>
</div>
<div class="content">
    <div class="errorTip hide">*对不起,您输入的手机号码有误</div>
    <div class="input_group">
        <input type="text" name="mobile" placeholder="请输入您的电话号"/>
        <a href="#">领取</a>
    </div>
</div>
<form name="batchKey" action="" method="post">
    <input type="hidden" name="mobile">
    <input type="hidden" name="couponBatchKey">
</form>
<script src="/old/common/js/zepto.min.js"></script>
<script src="/old/common/common/js/base.js"></script>
<script>
    (function (doc, win) {
        var docEl = doc.documentElement,
                resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
                recalc = function () {
                    var clientWidth = docEl.clientWidth;
                    if (!clientWidth) return;
                    // 针对uc横竖屏rem html没有重绘的问题
                    var style;
                    if (style = document.getElementById("forhtml")) {
                        style.parentNode.removeChild(style);
                    }
                    style = document.createElement("style");
                    style.id = "forhtml";
                    document.head.appendChild(style);
                    style.appendChild(document.createTextNode("html{font-size:" + 20 * (clientWidth / 320) + "px !important;}"));
                };
        recalc();
        if (!doc.addEventListener) return;
        win.addEventListener(resizeEvt, recalc, false);
        doc.addEventListener('DOMContentLoaded', recalc, false);
    })(document, window);
    //电话号码验证
    function mobileValidate(mobile) {
        var validateObj = {
            flag: true,
            msg: ''
        };
        var $mobile = $.trim(mobile);
        if ($mobile == '') {
            validateObj.flag = false;
            validateObj.msg = '请输入手机号码'
        } else if (!/^0?(13|14|15|17|18)[0-9]{9}$/.test($.trim(mobile)) && !/^(08|09|06)[0-9]{8}$/.test($.trim(mobile))) {
            validateObj.flag = false;
            validateObj.msg = '手机号格式错误'
        }
        return validateObj;
    }
    var $errorTip  = $('.errorTip');
    $('.input_group a').click(function(e){
        var $this = $(this);
        var mobile = $('input[name=mobile]').val();
        e.preventDefault();
        e.stopPropagation();
        $this.addClass('disabled');
        var Vmobile = mobileValidate(mobile);
        if(!Vmobile.flag){
            $errorTip.html(Vmobile.msg).removeClass('hide');
            $this.removeClass('disabled');
        }else{
            $.ajax({
                type: 'POST',
                url: '',
                data: {
                    mobile: $.trim(mobile)
                },
                success: function (data) {
                    $this.removeClass('disabled');
                    $errorTip.addClass('hide');
                    var dataJson = JSON.parse(data);
                    if (dataJson.code == 0) {
                        $('form[name=batchKey]').attr('action', dataJson.url).find('input[name=mobile]').attr('value', dataJson.data.mobile);
                        $('form[name=batchKey]').find('input[name=couponBatchKey]').attr('value', dataJson.data.batchKey);
                        $('form[name=batchKey]').submit();
                    } else {
                        $.confirm({
                            title: dataJson.msg,
                            detail: '',
                            yes: '确认'
                        });
                    }
                },
                error: function (data) {
                    $this.removeClass('disabled');
                    $errorTip.addClass('hide');
                    $.confirm({
                        title: '网络异常,请重试',
                        detail: '',
                        yes: '确认'
                    });
                }
            })
        }
    });
</script>
</body>
</html>
